<template>
  <div class="pages-container">

    <!-- 搜索框 Or 工具框 -->
    <a-form class="pages-tools-box" :form="form" @submit="getSearch">
      <a-row :gutter="[15, 10]">
        <a-col :span="4">
          <a-form-item>
            <a-input allowClear placeholder="企业名称" v-decorator="['title']"/>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :span="24" :style="{ textAlign: 'right' }">
          <a-button type="primary" html-type="submit">搜索</a-button>
          <a-button :style="{ marginLeft: '8px' }" @click="handleReset">清空</a-button>
          <a-button :style="{ marginLeft: '8px' }" @click="add">新增</a-button>
        </a-col>
      </a-row>
    </a-form>

    <!-- 表格 -->
    <div class="pages-content">
      <a-table :columns="columns" :data-source="data" :pagination="false" rowKey="id" :loading="tableLoading">
        <a-space slot="certImage" slot-scope="row">
          <img :src="row.certImage" style="max-width: 40px; max-height: 40px" @click="lookPhoto(row.certImage)">
        </a-space>
      </a-table>
    </div>

    <!-- 分页 -->
    <a-pagination class="pagination" show-quick-jumper :default-current="current_page" :total="total"
                  @change="changePages"/>

  </div>
</template>

<script>
const columns = [
  {title: 'ID', dataIndex: 'id'},
  {title: '公司全称', dataIndex: 'title'},
  {title: '简称', dataIndex: 'shortTitle'},
  {title: '营业执照', scopedSlots: {customRender: 'certImage'}},
];

import config from "../../tools/config";

export default {
  name: "List.vue",
  data() {
    return {
      // 公用配置
      Config: {},
      // 分页数据
      current_page: 1,
      total: 100,
      // table数据
      tableLoading: false,
      columns,
      data: [],
      // 搜索表单
      form: this.$form.createForm(this),
      // other
      UserStateList: [],
      defaultValue: 1,
    };
  },
  created() {
    const _this = this
    this.Config = config
    setTimeout(() => {
      _this.getData()
    }, 0)
  },
  methods: {
    add() {
      this.$router.push("/Home/User/CompanyDetail");
    },
    /**
     * 进行搜索
     * @param e
     */
    getSearch(e) {
      e.preventDefault();
      this.form.validateFields((error) => {
        if (!error) {
          this.getData(1)
        }
      });
    },

    /**
     * 请求Table数据
     * @param pages
     */
    getData(pages = 1) {
      this.tableLoading = true
      this.Http.get('/admin/supplier/getAll', {
        page: pages,
        type: 2,
        ...this.form.getFieldsValue()
      }).then(res => {
        this.tableLoading = false
        if (res.code === 1) {
          this.data = res.data.data
          this.current_page = res.data.current_page
          this.total = res.data.total
        } else {
          this.$message.error(res.msg)
        }
      }).catch(() => {
        this.tableLoading = false
      })
    },

    /**
     * 切换分页时
     * @param event
     */
    changePages(event) {
      this.getData(event)
    },

    /**
     * 清空搜索项
     */
    handleReset() {
      this.form.resetFields();
      this.getData()
    },
    lookPhoto(src) {
      this.Util.lookPhoto(src)
    },


  },
}
</script>

<style scoped>

</style>
